#include "entitymanager.h"
#include <cassert>

EntityManager* EntityManager::Instance()
{
	static EntityManager instance;

	return &instance;
}

/*-------------------------------------------------------------------------------------------------------------*/
BaseGameEntity* EntityManager::GetEntityByID(int id)const
{
	//find the entity
	EntityMap::const_iterator ent = m_entityMap.find(id);

	//assert that the entity is a member of the map
	assert ( (ent !=  m_entityMap.end()) && "<EntityManager::GetEntityFromID>: invalid ID");

	return ent->second;
}

/*-------------------------------------------------------------------------------------------------------------*/
void EntityManager::RemoveEntity(BaseGameEntity* pEntity)
{    
	m_entityMap.erase(m_entityMap.find(pEntity->ID()));
} 


/*-------------------------------------------------------------------------------------------------------------*/
void EntityManager::RegisterEntity(BaseGameEntity* NewEntity)
{
	m_entityMap.insert(std::make_pair(NewEntity->ID(), NewEntity));
}

